From 7ffbeb40de73d3facdadfc27b96b3795970a2069 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 20 Feb 2008 17:47:58 +0000 Subject: [PATCH] ioemu: Share framebuffer between VGA device model and VNC server. Now that the qemu WMVi patch is applied we can take full advantage of it sharing the video buffer between the vga driver and the qemu vnc server. This saves a lot of memcpy. It's worth mentioning again that when the guest colour depth is 24 bit we cannot share the buffer because 24 bpp is not supported by the vnc protocol, so we still have to do the translation 24 bpp -> 32 bpp. Signed-off-by: Stefano Stabellini --- tools/ioemu/hw/vga.c | 22 ++++++++++++---------- tools/ioemu/vl.h | 1 + tools/ioemu/vnc.c | 44 +++++++++++++++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/tools/ioemu/hw/vga.c b/tools/ioemu/hw/vga.c index 4e2f9525a7..7c62716642 100644 --- a/tools/ioemu/hw/vga.c +++ b/tools/ioemu/hw/vga.c @@ -1135,8 +1135,6 @@ static void vga_draw_text(VGAState *s, int full_update) } depth = s->get_bpp(s); - if (depth == 24) - depth = 32; if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) s->ds->dpy_colourdepth(s->ds, depth); if (width != s->last_width || height != s->last_height || @@ -1557,10 +1555,10 @@ static void vga_draw_graphic(VGAState *s, int full_update) vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)]; depth = s->get_bpp(s); - if (depth == 24) - depth = 32; - if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) - s->ds->dpy_colourdepth(s->ds, depth); + if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) { + if (depth != 24 || s->ds->depth != 32) + s->ds->dpy_colourdepth(s->ds, depth); + } if (disp_width != s->last_width || height != s->last_height) { dpy_resize(s->ds, disp_width, height); @@ -1570,7 +1568,9 @@ static void vga_draw_graphic(VGAState *s, int full_update) s->last_height = height; full_update = 1; } - if (s->cursor_invalidate) + if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4)) + s->ds->data = s->vram_ptr + (s->start_addr * 4); + if (!s->ds->shared_buf && s->cursor_invalidate) s->cursor_invalidate(s); line_offset = s->line_offset; @@ -1621,9 +1621,11 @@ static void vga_draw_graphic(VGAState *s, int full_update) page_min = page0; if (page_max == 0 || page1 > page_max) page_max = page1; - vga_draw_line(s, d, s->vram_ptr + addr, width); - if (s->cursor_draw_line) - s->cursor_draw_line(s, d, y); + if (!s->ds->shared_buf) { + vga_draw_line(s, d, s->vram_ptr + addr, width); + if (s->cursor_draw_line) + s->cursor_draw_line(s, d, y); + } } else { if (y_start >= 0) { /* flush to display */ diff --git a/tools/ioemu/vl.h b/tools/ioemu/vl.h index ae691b6131..2efa0112df 100644 --- a/tools/ioemu/vl.h +++ b/tools/ioemu/vl.h @@ -935,6 +935,7 @@ struct DisplayState { void *opaque; int switchbpp; + int shared_buf; void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h); void (*dpy_resize)(struct DisplayState *s, int w, int h); diff --git a/tools/ioemu/vnc.c b/tools/ioemu/vnc.c index 7f87f8ed18..60174070ca 100644 --- a/tools/ioemu/vnc.c +++ b/tools/ioemu/vnc.c @@ -336,11 +336,21 @@ static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, static void vnc_dpy_resize(DisplayState *ds, int w, int h) { + static int allocated; int size_changed; VncState *vs = ds->opaque; int o; - ds->data = realloc(ds->data, w * h * vs->depth); + if (!ds->shared_buf) { + if (allocated) + ds->data = realloc(ds->data, w * h * vs->depth); + else + ds->data = malloc(w * h * vs->depth); + allocated = 1; + } else if (allocated) { + free(ds->data); + allocated = 0; + } vs->old_data = realloc(vs->old_data, w * h * vs->depth); vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0])); vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0])); @@ -538,6 +548,11 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_ VncState *vs = ds->opaque; int updating_client = 1; + if (ds->shared_buf) { + framebuffer_set_updated(vs, dst_x, dst_y, w, h); + return; + } + if (src_x < vs->visible_x || src_y < vs->visible_y || dst_x < vs->visible_x || dst_y < vs->visible_y || (src_x + w) > (vs->visible_x + vs->visible_w) || @@ -1409,9 +1424,6 @@ static void set_pixel_format(VncState *vs, vs->blue_shift = blue_shift; vs->blue_max = blue_max; vs->pix_bpp = bits_per_pixel / 8; - - vga_hw_invalidate(); - vga_hw_update(); } static void pixel_format_message (VncState *vs) { @@ -1468,16 +1480,26 @@ static void pixel_format_message (VncState *vs) { static void vnc_dpy_colourdepth(DisplayState *ds, int depth) { int host_big_endian_flag; - struct VncState *vs; - - if (!depth) return; - + struct VncState *vs = ds->opaque; + + switch (depth) { + case 24: + ds->shared_buf = 0; + depth = 32; + break; + case 0: + ds->shared_buf = 0; + return; + default: + ds->shared_buf = 1; + break; + } + #ifdef WORDS_BIGENDIAN host_big_endian_flag = 1; #else host_big_endian_flag = 0; -#endif - vs = ds->opaque; +#endif switch (depth) { case 8: @@ -2312,7 +2334,7 @@ void vnc_display_init(DisplayState *ds) vs->ds->width = 640; vs->ds->height = 400; - vnc_dpy_colourdepth(vs->ds, 32); + vnc_dpy_colourdepth(vs->ds, 24); } #if CONFIG_VNC_TLS -- 2.30.2